<?
if($_SESSION['dtype']!=5) header("Location:home.html");
include("common/header.html");
include_once("class/ProductInfo.php");
include_once("class/Member.php");
$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];
$s = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));
$memberID=$_SESSION['memberID'];
$pid=abs($_REQUEST['pid']);
$aid=$_REQUEST['aid'] ? $_REQUEST['aid']+0:0;
$p=new ProductInfo($s,$pid,$aid);
$ptypes=ProductInfo::$ptype;
$p_info=$p->pInfo();
$fid=abs($_REQUEST['did'])?abs($_REQUEST['did']):$p_info['apply_did'];

$m=new GuestMember($s,$memberID,$fid);
$p->saleCheck();
$begintime=$p->getMinValidTime($begintime);/*产品有效起始日期*/
if($begintime==-1){
	getOut("index.html","无有效出行日期，请更换产品");
}

if(!$p->supply($fid)){
	getOut("index.html","无购买权限");
}	
//分销商id
$jsprice=$p->jsPrice($memberID,$begintime);
$uprice=$p->uPrice($memberID,$begintime);
$buynum=$p_info['buy_limit_low']?$p_info['buy_limit_low']:1;
//附属产品
$products=array();
$products[]=array("pid"=>$pid,"id"=>"purchaseNum","name"=>"tnum","ttitle"=>$p_info['ttitle'],"buynum"=>$buynum,"jsprice"=>$jsprice,"uprice"=>$uprice,"tprice"=>$p_info['tprice'],"minTime"=>$begintime,"ddays"=>$p_info['ddays'],"buy_limit_low"=>$p_info['buy_limit_low']);
if($p_info['p_type']=="A"||$p_info['p_type']=="B"||$p_info['p_type']=="D"){
	$c_pros=$m->salePros($p_info['lid']);
	foreach($c_pros as $row){
		$c_pids[]=$row['pid'];
	}
	foreach($c_pids as $c_pid){
		if($c_pid==$p_info['pid']) continue;
		$apro=new ProductInfo($s,$c_pid);
		try{
			$c_jsprice=$apro->jsPrice($memberID,$begintime);
			$c_uprice=$apro->uPrice($memberID,$begintime);
			$c_pro=$apro->pInfo();
			$time=strtotime($begintime)+($c_pro['ddays']-$p_info['ddays'])*24*3600;
			$minTime=date("Y-m-d",$time);
			$products[]=array("pid"=>$c_pro['id'],"id"=>$c_pro['id'],"name"=>"c_pids[".$c_pid."]","ttitle"=>$c_pro['ttitle'],"buynum"=>0,"jsprice"=>$c_jsprice,"uprice"=>$c_uprice,"tprice"=>$c_pro['tprice'],"minTime"=>$minTime,"buy_limit_low"=>$c_pro['buy_limit_low']);
		}catch(Exception $e){
			//结算价未设置
		}
	}
}
//产品说明
$timeTitle=($p_info['ddays']==0)?"有效期内，可预订当天门票":"有效期内，需提前".($p_info['ddays'])."天预订";
$unitT=$p_info['p_type']=="C"?"间":"张";
$tips=$p_info['ddays']>0?"需提前".$p_info['ddays']."天预订，":"可预订当日票，";
$tips.=$p_info['buy_limit_low']>0?$p_info['buy_limit_low'].$unitT."起订，":"1".$unitT."起订，";
if($p_info['p_type']=="A"){
	$tips.=($p_info['delaydays']>0)?"游玩日期起".$p_info['delaydays']."天内有效，":"游玩日期当日有效，";
}
$tips.=($p_info['status']!=0)?"<i>".($p_info['mdays']!=0?"自动":"人工")."确认</i>后生效，":"";
$tips=$tips.$p_info['notes'];
//金额
$operator=new Member($s,$_SESSION['memberID']);
$v['money']=$operator->money()/100;
$m_info=$operator->info();
include("tpl/productSale.tpl");
include("common/footer.html");
?>
	